package com.sniff.atp.enums.status;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum DeliveryStatusEnum {

    /**
     * 发货状态
     */
    wait_shelves(-1, "待上架"),
    wait_deal(0, "待处理"),
    picking(1, "拣货中"),
    labeling(2, "打标中"),
    packing(3, "打包中"),
    pack_finish(4, "打包完成"),
    delivered(5, "已发货"),

    cancelled(10, "已取消"),
    ;

    private final Integer status;
    private final String desc;

    public static DeliveryStatusEnum getByCode(Integer deliveryStatus) {
        if (deliveryStatus == null) {
            return null;
        }
        for (DeliveryStatusEnum statusEnum : values()) {
            if (statusEnum.getStatus().equals(deliveryStatus)) {
                return statusEnum;
            }
        }
        return null;
    }

    public Integer getStatus() {
        return status;
    }

    public String getDesc() {
        return desc;
    }

    DeliveryStatusEnum(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    public static boolean picking(Integer status) {
        return picking.getStatus().equals(status);
    }

    /**
     * 打包已完成
     *
     * @param status
     * @return
     */
    public static boolean hasPackFinish(Integer status) {
        return status != null && status >= pack_finish.getStatus();
    }

    /**
     * 未发货校验
     *
     * @param status
     * @return 发货或者取消 返回false;未发货返回true
     */
    public static boolean hasUndelivery(Integer status) {
        return status != null && status < delivered.getStatus();
    }

    public static List<Integer> getUndelivery() {
        return Arrays.stream(values())
                .filter(x -> hasUndelivery(x.getStatus()))
                .map(x -> x.getStatus())
                .collect(Collectors.toList());
    }

    /**
     * 是否可以打标
     */
    public static boolean needLable(Integer status) {
        return status != null && status >= labeling.getStatus();
    }

}
